package cz.boxdesign.library.common.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import cz.boxdesign.library.entity.Author;
import cz.boxdesign.library.entity.Book;
import cz.boxdesign.library.entity.Publisher;
import cz.boxdesign.library.entity.Napsal;
import cz.boxdesign.library.entity.Department;
import cz.boxdesign.library.entity.Pujceno;
import cz.boxdesign.library.entity.Reservation;
import cz.boxdesign.library.entity.User;
import cz.boxdesign.library.entity.dao.EntityDao;

@Component("commonDao")
public class CommonDaoImpl implements CommonDao {

  @Autowired
  @Qualifier("autorDao")
  private EntityDao autorDao;

  @Autowired
  @Qualifier("oddeleniDao")
  private EntityDao oddeleniDao;

  @Autowired
  @Qualifier("nakladatelstviDao")
  private EntityDao nakladatelstviDao;

  @Autowired
  @Qualifier("knihaDao")
  private EntityDao knihaDao;

  @Autowired
  @Qualifier("pujcenoDao")
  private EntityDao pujcenoDao;

  @Autowired
  @Qualifier("userDao")
  private EntityDao userDao;

  @Autowired
  @Qualifier("napsalDao")
  private EntityDao napsalDao;

  @Autowired
  @Qualifier("rezervaceDao")
  private EntityDao rezervaceDao;

  public CommonDaoImpl() {
    super();
  }

  @Override
  public EntityDao getDao(Class entity) {
    if (entity.getName().equals(Author.class.getName())) {
      return autorDao;
    } else if (entity.getName().equals(Publisher.class.getName())) {
      return nakladatelstviDao;
    } else if (entity.getName().equals(User.class.getName())) {
      return userDao;
    } else if (entity.getName().equals(Department.class.getName())) {
      return oddeleniDao;
    } else if (entity.getName().equals(Book.class.getName())) {
      return knihaDao;
    } else if (entity.getName().equals(Napsal.class.getName())) {
      return napsalDao;
    } else if (entity.getName().equals(Pujceno.class.getName())) {
      return pujcenoDao;
    } else if (entity.getName().equals(Reservation.class.getName())) {
      return rezervaceDao;
    }

    return null;
  }
}
